package com.hundred.category.module.screen;

import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.codehaus.jackson.map.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.hundred.category.dao.CategoryDao;
import com.hundred.category.dao.dataobject.CategoryDo;

/**
 * 类目列表JSON
 * 
 * @author Administrator
 */
public class Catelistjson {

	private static final Logger log = LoggerFactory.getLogger(Catelistjson.class);


	private CategoryDao categoryDao;

	@Autowired
	private HttpServletRequest request;
	
	@Autowired
	private HttpServletResponse response;

	public void execute() {
		response.addHeader("Cache-Control", "no-cache");
		response.setContentType("application/json");
		String parentIdStr = request.getParameter("id");
		try {
			List<CategoryDo> pCate = categoryDao.queryAllEnableCategoryByParentId(Long.valueOf(parentIdStr));
			ObjectMapper mapper = new ObjectMapper();
			PrintWriter pw = response.getWriter();
			mapper.writeValue(pw, pCate);
			
			
			
			
			pw.flush();
			pw.close();
		} catch (Exception e) {
			log.error("Catelistjson error . parentIdStr=" + parentIdStr, e);
		}
		return;
	}

}
